﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MO.BusinessServer
{
    public class MessageManager : BaseManager
    {
        static Dictionary<string, List<MessageItem>> messDict = new Dictionary<string, List<MessageItem>>();
        public MessageManager(object context)
        {
            base.Init(context);
        }
        public static void SendMessage(MessageItem message)
        {
            if (!messDict.ContainsKey(message.UserCode))
                messDict.Add(message.UserCode, new List<MessageItem>());
            messDict[message.UserCode].Add(message);
        }
        public MessageItem GetMessage()
        {
            List<MessageItem> messList = null;
            messDict.TryGetValue(this.Context.User.Code,out messList);
            if (messList != null && messList.Count > 0)
            {
                var mess = messList[0];
                messList.RemoveAt(0);
                return mess;
            }
            return null;
        }
    }
    public class MessageItem
    {
        public string Type;
        public string UserCode;
        public string Title;
        public string Content;
        public string Url;
    }
    public class MessageType
    {
        public const string Form = "form";
        public const string Prompt = "prompt";
    }
}
